package org.icop.utils;

import java.util.HashMap;
import java.util.Map;

import org.jbpt.algo.graph.TransitiveClosure;
import org.jbpt.graph.abs.IDirectedEdge;
import org.jbpt.graph.abs.IDirectedGraph;
import org.jbpt.hypergraph.abs.IVertex;

public class TransitiveClosureCache {

	private static TransitiveClosureCache eInstance = null;
	
	public static TransitiveClosureCache getInstance() {
		if (eInstance == null)
			eInstance = new TransitiveClosureCache();
		
		return eInstance;
	}
	
	private Map<IDirectedGraph<IDirectedEdge<IVertex>, IVertex>, TransitiveClosure<IDirectedEdge<IVertex>, IVertex>> closures = new HashMap<>();
	
	public TransitiveClosure<IDirectedEdge<IVertex>, IVertex> getTransitiveClosureForGraph(IDirectedGraph<IDirectedEdge<IVertex>, IVertex> g) {
		if (!this.closures.containsKey(g))
			this.closures.put(g,new TransitiveClosure<IDirectedEdge<IVertex>, IVertex>(g));
		
		return this.closures.get(g);
	}
}
